#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read<int>()
#define inn read<ll>()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

template <typename T>
T read(){
	T x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 2e4+10;

int n,dfn[N],siz[N],son[N],top[N],ind[N],fa[N],dep[N],h[N],cnt,tim,q;
ll luck[N];

struct edge{int v,nxt;}e[N<<1];
void link(int x,int y){e[++cnt] = (edge){y,h[x]};h[x] = cnt;}

struct node{
	ll arr[62];
	node(int x = 0){memset(arr,0,sizeof(arr));}
	bool insert(ll x){
		for(int i = 60;~i&&x;i--)
			if(x >> i & 1){
				if(arr[i]) x ^= arr[i];
				else return arr[i] = x,1;
			}
		return 0;
	}
	const ll operator [](int x)const{return arr[x];}
	ll operator [](int x){return arr[x];}
	friend node operator + (node a,node b){
		node ans = a;
		for(int i = 60;~i;i--)
			if(b[i]) ans.insert(b[i]);
		return ans;
	}
	ll getmax(){
		ll res = 0;
		for(int i = 60;~i;i--)
			if((res ^ arr[i]) > res) res ^= arr[i];
		return res;
	}
}val[N<<2];

bool update(int pos,ll v,int o = 1,int l = 1,int r = n){
	if(l == r) return val[o] = node(0),val[o].insert(v);
	int mid = l+r>>1; bool f = 0;
	if(pos <= mid) f = update(pos,v,o<<1,l,mid);
	else f = update(pos,v,o<<1|1,mid+1,r);
    if(f) val[o] = val[o<<1] + val[o<<1|1];
	return f;
}

node query(int xl,int xr,int o = 1,int l = 1,int r = n){
	if(xl == l && xr == r) return val[o];
	int mid = l+r>>1;
	if(xr <= mid) return query(xl,xr,o<<1,l,mid);
	else if(xl > mid) return query(xl,xr,o<<1|1,mid+1,r);
	else return query(xl,mid,o<<1,l,mid) + query(mid+1,xr,o<<1|1,mid+1,r);
}

ll qtree(int x,int y){
	node ans;
	while(top[x] != top[y]){
		if(dep[top[x]] < dep[top[y]]) swap(x,y);
		ans = ans + query(dfn[top[x]],dfn[x]);
		x = fa[top[x]];
	}if(dfn[x] > dfn[y]) swap(x,y);
	ans = ans + query(dfn[x],dfn[y]);
	return ans.getmax();
}

void dfs(int x,int p){
	dep[x] = dep[p]+1; fa[x] = p; siz[x] = 1;
	for(int i = h[x],y;i;i = e[i].nxt){
		if((y = e[i].v) == p) continue;
		dfs(y,x); siz[x] += siz[y]; if(siz[y] > siz[son[x]]) son[x] = y;
	}
}

void dfs(int x){
	dfn[x] = ++tim; ind[tim] = x; update(dfn[x],luck[x]); top[x] = (son[fa[x]] == x) ? top[fa[x]] : x; if(son[x]) dfs(son[x]);
	for(int i = h[x],y;i;i = e[i].nxt){
		if((y = e[i].v) == fa[x] || y == son[x]) continue;
		dfs(y);
	}
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,q = in;
	for(int i = 1;i <= n;i++) luck[i] = inn;
	for(int i = 1;i < n;i++){
		int x = in,y = in; link(x,y); link(y,x);
	} dfs(1,0);dfs(1);
	while(q--){
		int x = in,y = in;
		printf("%lld\n",qtree(x,y));
	}
	return 0;
}
